package com.hedl.elasticsearch.controller;

import com.hedl.elasticsearch.exception.DiyException;
import com.hedl.elasticsearch.pojo.PageResult;
import com.hedl.elasticsearch.pojo.RequestParams;
import com.hedl.elasticsearch.service.IHotelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.IOException;
import java.rmi.RemoteException;
import java.util.List;
import java.util.Map;

/**
 * @author Big Watermelon
 * @description
 * @date 2023/11/08/1:27
 */
@Slf4j
@RequestMapping("/hotel")
@RestController
public class HotelController {

    @Resource
    private IHotelService iHotelService;

    @PostMapping("/list")
    public PageResult search(@RequestBody RequestParams requestParams) throws IOException {
        return iHotelService.search(requestParams);
    }

    @PostMapping("/bool")
    public PageResult boolQuery(@ RequestBody RequestParams requestParams) throws IOException {
        return iHotelService.boolQuery(requestParams);
    }

    @PostMapping("/distance")
    public PageResult distanceSort(@RequestBody RequestParams requestParams) throws IOException {
        return iHotelService.distanceSort(requestParams);
    }

    @PostMapping("/functionScore")
    public PageResult functionScore(@RequestBody RequestParams requestParams) throws IOException{
        return iHotelService.functionScore(requestParams);
    }

    @PostMapping("/filters")
    public Map<String, List<String>> filters(@RequestBody RequestParams requestParams) throws IOException{
        return iHotelService.filters(requestParams);
    }

    @GetMapping("/suggestion/{key}")
    public List<String> suggestion(@PathVariable(value = "key") String key) throws IOException{
        if (key != null && !"".equals(key)){
            return iHotelService.suggestion(key);
        }else{
            DiyException.cast("key 为 null");
            return null;
        }
    }
}
